<!doctype html>
<html lang="en">

<head>
	<title>鑫洋泉运营管理平台</title>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<!-- VENDOR CSS -->
	<link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="../assets/vendor/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../assets/vendor/dataTables/jquery.dataTables.min.css">
	<link rel="stylesheet" href="../assets/vendor/linearicons/style.css">
	<!-- MAIN CSS -->
	<link rel="stylesheet" href="../assets/css/main.css">
	<!-- FOR DEMO PURPOSES ONLY. You should remove this in your project -->
	<link rel="stylesheet" href="../assets/css/demo.css">
	<link rel="stylesheet" href="../assets/css/sweetalert.css">
	<!-- GOOGLE FONTS -->
	<!--<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700" rel="stylesheet">-->
	<!-- ICONS -->
	<link rel="apple-touch-icon" sizes="76x76" href="../assets/img/apple-icon.png">
	<link rel="icon" type="image/png" sizes="96x96" href="../assets/img/favicon.png">
</head>

<body>
	<!-- WRAPPER -->
	<div id="wrapper">
		<!-- NAVBAR -->
		<nav class="navbar navbar-default navbar-fixed-top">
			<h1 class="header_1">
				 鑫洋泉运营管理系统 
			</h1>
		</nav>
		<!-- END NAVBAR -->
		<!-- LEFT SIDEBAR -->
		<div id="sidebar-nav" class="sidebar">
			<div class="sidebar-scroll">
				<nav>
					<ul class="nav">
                        <li><a href="index.html" class="active"><i class="lnr lnr-home"></i> <span>首页</span></a></li>
                        <li><a href="device.html" class=""><i class="lnr lnr-chart-bars"></i> <span>车辆信息</span></a></li>
                        <li><a href="custom.html" class=""><i class="lnr lnr-chart-bars"></i> <span>客户信息</span></a></li>
                         
                        <li>
                            <a href="#"><i class="lnr lnr-chart-bars"></i> <span>SIM卡管理</span></a>
                            <ul class="nav">
                                <li><a href="cardsStatistics.html">统计信息</a></li>
                                <li><a href="cardsList.html">列表信息</a></li>
                            </ul>
                        </li>
                        <li>
							<a href="config.html"><i class="lnr lnr-chart-bars"></i> <span>配置管理</span></a>
							<ul class="nav">
								<li><a href="config.html" class=""><span>默认配置列表</span></a></li>
								<li><a href="parameters.html?1" class=""><span>解码类型</span></a></li>
								<li><a href="parameters.html?2" class=""><span>主机盒界面</span></a></li>
								<li><a href="parameters.html?3" class=""><span>前景和前后视角</span></a></li>
								<li><a href="parameters.html?4" class=""><span>转向视角</span></a></li>
								<li><a href="parameters.html?5" class=""><span>轨迹线类型</span></a></li>
						
							</ul>
						</li><!--<li><a href="device_detail.html" class=""><i class="lnr lnr-cog"></i> <span>设备详情</span></a></li>-->
                    </ul>
				</nav>
			</div>
		</div>
		<!-- END LEFT SIDEBAR -->
		<!-- MAIN -->
		<div class="main">
			<!-- MAIN CONTENT -->
			<div class="main-content">
				<div class="container-fluid">
                    <div class="row">
                        <div class="col-md-11">
					            <h3 class="page-title" id="typeTitle"></h3>
                        </div>
                        <div class="col-md-1">
                            <!--<form class="navbar-form navbar-right">-->
                                    <span class="input-group-btn"><button type="button" onclick="showModal()" class="btn btn-primary">新增</button></span>
                        </div>
                    </div>

                    <div class="row">
                        <table id="example" class="col-md-12 display" cellspacing="0" width="100%">
                        </table>
					</div>
				</div>
			</div>
			<!-- END MAIN CONTENT -->
		</div>
        <!-- 模态框（Modal） -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="myModalLabel"></h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <label for="user_id" class="col-sm-3 control-label">名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="name" name="name" value=""
                                        placeholder="">
                                </div>
                            </div>
                       
                            <div class="form-group">
                                <label for="lastname" class="col-sm-3 control-label">值</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="value" value="" id="value"
                                        placeholder="">
                                </div>
                            </div>
                            
                            <input type="hidden" id="paramType">
                            <input type="hidden" id="id">
                            <input type="hidden" id="addOrEdit">
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onClick="doEdit()">保存</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!-- /.modal -->
		<!-- END MAIN -->
		<div class="clearfix"></div>
		<footer>
			<div class="container-fluid">
			</div>
		</footer>
	</div>
	<!-- END WRAPPER -->
	<!-- Javascript -->
	<script src="../assets/vendor/jquery/jquery.min.js"></script>
	<script src="../assets/vendor/bootstrap/js/bootstrap.min.js"></script>
	<script src="../assets/vendor/jquery-slimscroll/jquery.slimscroll.min.js"></script>
    <script src="../assets/vendor/dataTables/jquery.dataTables.min.js"></script>
	<script src="../assets/scripts/klorofil-common.js"></script>
	<script src="../assets/vendor/sweetalert.min.js"></script>
    <script>
        var thisURL = document.URL;
		var type = thisURL.split('?')[1];
        var cleanData = function () {
            $('#name').val('');
            $('#value').val('');
            $('#id').val('');
        };

        (function(){
            var thisURL = document.URL;
		    var type = thisURL.split('?')[1];
            var value= '';
            $('#paramType')[0].value = type;

            switch(type) {
                case '1': value = '解码类型';
                    break;
                case '2': value = '主机盒界面';
                    break;
                case '3': value = '前景和前后视角';
                    break;
                case '4': value = '转向视角';
                    break;
                case '5': value = '轨迹线类型';
                    break;
            }
            $('#typeTitle')[0].innerHTML = value;

        })();


        var add = function () {
            var type = $('#paramType')[0].value;

        }
        var showModal = function (data) {
            // $('#myModal').modal(data);
            if(data) {
                $('#name')[0].value = data.name;
                $('#value')[0].value = data.value;
                $('#id')[0].value = data.id;

                $('#addOrEdit')[0].value = 'edit';
            } else {
                cleanData();
                $('#addOrEdit')[0].value = 'add';
            }
            
            $('#myModal').modal('show');
        }
        var doEdit = function () {
            //{ id, mobile, nickName, sex, birthday, created }
            var data = {}, url;
            data.name = $('#name')[0].value;
            data.value = $('#value')[0].value;
            if ($('#addOrEdit')[0].value == 'add') {
                data.parmType = $('#paramType')[0].value;
                url = '../ws/0.1/param/pd';
            } else {
                data.id = $('#id')[0].value;
                url = '../ws/0.1/param/pd/update';
            }
            //add  http://localhost:8080/oss/ws/0.1/param/pd

            //edit http://localhost:8080/oss/ws/0.1/param/pd/update
            
            doAjax(data, url);
        }
        var doAjax = function (data, url) {
            $.ajax(
                {
                    url: url,
                    // url: "../ws/0.1/vehicle",
                    // data: data,
                    type: "post",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(data),
                    dataType: "json",
                    beforeSend:function()
                    {
                        $("#tip").html("<span style='color:blue'>正在处理...</span>");
                        return true;
                    },
                    success:function(data)
                    {
                // "url": "../ws/0.1/vehicle/datas",
                        if(data.code == 200)
                        {
                            table.ajax.url("../ws/0.1/param/pd?paramType=" + type).load();
                            $("#successMessage").html("修改成功");
                            $("#myAlert").alert();

                            // table.ajax.url('../ws/0.1/vehicle/datas').load();
                        }
                        else
                        {
                            $("#warningMessage").html(data.message);
                            alert(data.message);
                        }
                        $('#myModal').modal('hide');
                    },
                    error: function()
                    {
                        alert('请求出错');
                    },
                    complete: function()
                    {
                        $('#acting_tips').hide();
                    }
                });
        }
        var deleteParameters = function (id) {
            swal({
                title: "确定删除吗？",    
                type: "warning",   
                showCancelButton: true,    
                confirmButtonColor: "#DD6B55",
                cancelButtonText: "取消", 
                confirmButtonText: "确定！",    
                closeOnConfirm: false }, 
                function() { 
                
                    $.ajax(
                        {
                            //oss/ws/0.1/param/pd?
                            url: "../ws/0.1/param/pd?id=" + id,
                            // url: "../ws/0.1/vehicle",
                            // data: data,
                            type: "delete",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            beforeSend:function()
                            {
                                $("#tip").html("<span style='color:blue'>正在处理...</span>");
                                return true;
                            },
                            success:function(data)
                            {
                        // "url": "../ws/0.1/vehicle/datas",
                                if(data.code == 200)
                                {
                                    table.ajax.url("../ws/0.1/param/pd?paramType=" + type).load();
                                    swal("删除！", "删除成功", "success"); 
                                    // table.ajax.url('../ws/0.1/vehicle/datas').load();
                                }
                                else
                                {
                                    sweetAlert("error", data.message,"error");
                                }
                            },
                            error: function()
                            {
                                sweetAlert("error", "请求出错","error");
                            },
                            complete: function()
                            {
                            }
                        });
                });

        }

        var loadTable = function() {

        }

    var table = $('#example').DataTable( {
        oLanguage: {
            "sUrl": "../assets/vendor/dataTables/zh_CN.json"
        },
        //左下角信息
        info: false,
        //关闭行数选择
        "lengthChange": false,
        //关闭本地搜索
        "searching": false,
        //关系列排序
         "columns": [
            // { "orderable": false },
            // { "orderable": false },
            // { "orderable": false },
            // { "orderable": false },
            // { "orderable": false },
        ],
        "columnDefs": [
            {
                "targets": [0],
                "visible": false,
                "searchable": false
            }
        ],
        "fnDrawCallback"    : function(){
        　　this.api().column(1).nodes().each(function(cell, i) {
        　　　　cell.innerHTML =  i + 1;
        　　});
        },
      length: 10,
      
        // "ajax": '../assets/device_ajax.txt'
         //"serverSide": true,//分页，取数据等等的都放到服务端去
          //  "deferRender": true,//当处理大数据时，延迟渲染数据，有效提高Datatables处理能力
            "destory": true,
            "ajax": {
                "dataType": 'json',
                "type": "get",
                "url": "../ws/0.1/param/pd?paramType=" + type,
                // "url": "../ws/0.1/customer/datas",
                "data": function (d) {
                   //console.log(d)
                    // d.id = id;
                },
                "async": false
            },

            //{ id, mobile, nickName, sex, birthday, created } 
            //序列	名称	值	创建日期	修改日期	操作
            "columns": [
                {
                    "data": "id",
                    "title": ""
                }, {
                    'data': 'id',
                    "title": "序列"
                    
                }, {
                    "data": "name",
                    "title": "名称"
                }, {
                    "data": "value",
                    "title": "值"
                }, {
                    "data": "created",
                    "title": "创建日期"
                 }, {
                    "data": "updated",
                    "title": "修改日期"
                }, {
                    "data": function ( row, type, val, meta ) {
                        return row;
                    },
                    "title": "操作",
                    render: function (row, data) {

                        return "<a class='' href='#' onclick='showModal(" + JSON.stringify(row) + ")'>编辑</a><span>  </span>"+"<a class='' href='#' onclick='deleteParameters(" + row.id + ")'>删除</a>";
                    }
                }
            ]
    } );

    function search() {
        var id = $('#phone')[0];
		// var oSettings = table.fnSettings();
        if(id) {
            table.ajax.url('../ws/0.1/customer/data?mobile=' + id.value).load()
            // table.ajax.url('ws/0.1/vehicle/datas').load()
        }
    }
    
    </script>
</body>

</html>
